<!doctype html>
<!--suppress ALL -->
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>防绿帽系统注册</title>

    <!-- Bootstrap core CSS -->
    <link href="/bootstrap-4.0.0-dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="/stylesheets/login.css" rel="stylesheet">
    <script type="text/javascript" src="/javascripts/jquery-3.3.1.js"></script>
    <script type="text/javascript" src="/javascripts/jquery.cookie.js"></script>
</head>

<body class="text-center">
<div class="form-signin">
    <img class="mb-4" src="/images/logo.png" alt="" width="100" height="100">
    <h1 class="h3 mb-3 font-weight-normal title">欢迎注册</h1>
    <input type="" id="inputAccount" class="form-control" placeholder="请输入你的账号" required autofocus>
    <input type="password" id="inputPassword" class="form-control" placeholder="请输入密码" required>
    <input type="password" id="confirmPassword" class="form-control" placeholder="请确认密码" required>
    <div class="alert alert-warning hidden" id="hud" >注册失败</div>
    <button class="btn btn-lg btn-primary btn-success btn-block" id="registerBtn">注册并登录</button>
    <button class="btn btn-lg btn-primary btn-success btn-block" id="loginBtn">有账号，去登录</button>
    <p class="mt-5 mb-3 text-muted">© Wbqqqq</p>
</div>



</body>
</html>

<script src="javascripts/login.js"></script>
<script type="text/javascript">

     $('#loginBtn').click(function () {
         window.location.href='/login'
     })


    $('#registerBtn').click(function () {

       let inputAccount = $("#inputAccount").val()
       let inputPassword = $("#inputPassword").val()
       let confirmPassword = $("#confirmPassword").val()


        if (inputAccount.indexOf(" ") != -1) {
            $("#hud").text("账号不能有空格");
            $("#hud").show()
        }

        // if (inputPassword.indexOf(" ") != -1) {
        //     alert("没有空格");
        // } else {
        //     alert("有空格");
        // }



        if(!inputAccount.length) {
           $("#hud").text("账号不能为空");
           $("#hud").show()
           return
       }else {
           $("#hud").hide()
       }


       if(!confirmPassword.length || !inputPassword.length){
           $("#hud").text("密码不能为空");
           $("#hud").show()
           return
       }else {
           $("#hud").hide()
       }

       if (confirmPassword != inputPassword){
           $("#hud").text("两次密码不相同");
           $("#hud").show()
           return
       }else {
           $("#hud").hide()
       }

        register(inputAccount,inputPassword,(res)=>{
            console.log('接收到了回吊')
            console.log(res)
            if(res.code == 1){
                $.cookie("userToken",'Bearer ' + res.data.token);
                window.location.href='/'
            }else {
                $("#hud").text(res.msg);
                $("#hud").show()
            }
        });

    });

</script>



